package training;

import java.util.Arrays;

/**
 * @Author liangzai
 * @Description:
 */
public class J25_9_19_Training {
    //裁剪数字后查询第 K 小的数字
    public int[] smallestTrimmedNumbers(String[] nums, int[][] queries) {
        int[] res = new int[queries.length];
        for (int i = 0; i < queries.length; i++) {
            res[i] = help(nums, queries[i]);
        }
        return res;
    }
    private int help(String[] nums, int[] arr) {
        String[][] temp = new String[nums.length][2];
        for (int i = 0; i < nums.length; i++) {
            temp[i][0] = nums[i].substring(nums[i].length() - arr[1]);
            temp[i][1] = i + "";
        }
        Arrays.sort(temp, (a, b) -> {
            if (a[0].equals(b[0])) return Integer.valueOf(a[1]) - Integer.valueOf(b[1]);
            return a[0].compareTo(b[0]);
        });
        return Integer.valueOf(temp[arr[0] - 1][1]);
    }
}
